<template>
    <div class="container">
        <page-table 
        ref="pageTable"
        :func="options"
        @search="searchs"
        >
			<template v-slot:role="data">
				{{formatRole(data.data.row.roleId)}}
			</template>
			<template v-slot:sales="{data}">
				{{option.salesman.find(item=>item.value==data.row.sid)?.label}}
			</template>
			<template v-slot:avatar="data">
				<img :src="data.data.row.avatarUrl | getFilePath" alt="" style="width:30px;height:30px">

			</template>
			<template v-slot:moreoperation="{data}">
				<el-button type="warning" size="mini" @click="reset(data.row.id)">重置密码</el-button>
			</template>
        </page-table>
    </div>
</template>
<script>
import pageTable from "@/components/page-table.vue"
import {resetPassword} from "@/apis/user/index"
import options from "./index"
import {mapState} from "vuex"
import {getFilePath} from "@/filters/index"
export default {
	name:"user",
	components:{
		pageTable
	},
	filters:{getFilePath},
	data(){
		return {
			columns:[],
			reqOptions:{},
			search:{},
			operation:{},
			options
		}
	},
	methods:{
		searchs(){
			console.log("点击搜索")
		},
		formatRole(id){
			let role = this.role.find(item=>item.id==id)
			if(role){
				return role.name
			}
			return ""
		},
		reset(id){
			this.$confirm("将重置该用户的密码,是否继续", "提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "warning"
			}).then(() => {
				resetPassword(id)
			})
		}
	},
	computed:{
		...mapState(["role","option"]),
		// salesman(){
		// 	let option = [{label:"全部",value:0},...this.option.salesman]
			
		// 	// option.unshift({label:"全部",value:0})
		// 	return option
		// }
	},
	created(){

		//  columns:options.columns,
		//     reqOptions:options.reqOptions,
		//     search:options.search,
		//     operation:options.operation
	}
}
</script>